package artibella.ui.forms
{
	import artibella.IDisposable;
	import flash.display.DisplayObject;
	import flash.display.InteractiveObject;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author pbordachar
	 */
	
	public class ACheckButton extends Sprite implements IDisposable
	{
		protected var _selected:Boolean;
		
		public function ACheckButton( b:Boolean = false ) 
		{
			_selected = b;
			
			_init();
		}
		
		protected function _init():void
		{
			activate( true )
		}
		
		// - - -
		
		public function activate( b:Boolean ):void
		{
			if ( b ) {
				
				buttonMode = true;
				mouseChildren = false;
			
				addEventListener( MouseEvent.ROLL_OVER, _doRollOver );
				addEventListener( MouseEvent.ROLL_OUT, _doRollOut );
				addEventListener( MouseEvent.CLICK, _doClick );
				
			} else {
				
				removeEventListener( MouseEvent.ROLL_OVER, _doRollOver );
				removeEventListener( MouseEvent.ROLL_OUT, _doRollOut );
				removeEventListener( MouseEvent.CLICK, _doClick );
			}
		}
		
		// - - -
		
		protected function _doRollOver( e:MouseEvent ):void
		{
			// override this
		}
		
		protected function _doRollOut( e:MouseEvent ):void
		{
			// override this
		}
		
		protected function _doClick( e:MouseEvent ):void
		{
			_selected = !_selected
			
			// override this
		}
		
		// - - -
		
		public function get selected():Boolean
		{
			return _selected;
		}
		
		// - - -
		
		public function dispose():void
		{
			activate( false );
		}
	}
}